#include "InitLight.h"

InitLight::InitLight(void)
	{
	}
void  InitLight::Init(int width	, int length, int x, int z, bool first ){
	counter=0;
	this->width =width;
	this->length = length;
	this->x=x;
	this->z=z;
	blue.m_Light.Type=
	yellow.m_Light.Type=
	white.m_Light.Type=
	magenta.m_Light.Type=
	cyan.m_Light.Type=
	red.m_Light.Type=  D3DLIGHT_SPOT;

	blue.m_Light.Theta=
	yellow.m_Light.Theta=
	white.m_Light.Theta=
	magenta.m_Light.Theta=
	cyan.m_Light.Theta=
	red.m_Light.Theta= D3DX_PI/16;

	blue.m_Light.Phi=
	yellow.m_Light.Phi=
	white.m_Light.Phi=
	magenta.m_Light.Phi=
	cyan.m_Light.Phi=
	red.m_Light.Phi= D3DX_PI/16;


	blue.m_Light.Direction=		D3DXVECTOR3(0, -1.0f, 0);
	yellow.m_Light.Direction=	D3DXVECTOR3(0, -1.0f,0);
	white.m_Light.Direction=	D3DXVECTOR3(0, -1.0f,0);
	magenta.m_Light.Direction=	D3DXVECTOR3(0, -1.0f, 0);
	cyan.m_Light.Direction=		D3DXVECTOR3(0, -1.0f, 0);
	red.m_Light.Direction=		D3DXVECTOR3(0, -1.0f, 0);


	blue.m_Light.Range=
	yellow.m_Light.Range=
	white.m_Light.Range=
	magenta.m_Light.Range=
	cyan.m_Light.Range=
	red.m_Light.Range=			 30.0f;


	blue.SetPosition(0.05*length,15,0.05*width);
	yellow.SetPosition(0.5*length,15,0.05*width);
	white.SetPosition(0.95*length,15,0.05*width);
	magenta.SetPosition(0.05*length,15,0.95*width);
	cyan.SetPosition(0.5*length,15,0.95*width);
	red.SetPosition(0.95*length,15,0.95*width);

	blue.m_Light.Attenuation0=
	yellow.m_Light.Attenuation0=
	white.m_Light.Attenuation0=
	magenta.m_Light.Attenuation0=
	cyan.m_Light.Attenuation0=		
	red.m_Light.Attenuation0=		1;


	blue.SetDiffuse(1,1,0);
	yellow.SetDiffuse(1,1,0);
	white.SetDiffuse(1,1,0);
	magenta.SetDiffuse(1,1,0);
	cyan.SetDiffuse(1,1,0);
	red.SetDiffuse(1,1,0);

	blue.Enable(true);
	yellow.Enable(true);
	white.Enable(true);
	magenta.Enable(true);
	cyan.Enable(true);
	red.Enable(true);
	if(first){
	AddObject(blue);
	AddObject(yellow);
	AddObject(white);
	AddObject(magenta);
	AddObject(cyan);
	AddObject(red);
		}
counter=0;
animation =true;
	return;
	}
InitLight::~InitLight(void)
	{
	}

void InitLight::Render()
	{
	if(counter <= ANIMATION_LENGTH){
	blue.SetPosition(0.05*(float)length+((float)counter/(float)ANIMATION_LENGTH)*((float)x-0.05*(float)length),	15,	0.05*width+((float)counter/(float)ANIMATION_LENGTH)*((float)z-0.05*(float)width));
	yellow.SetPosition(0.5*(float)length+((float)counter/(float)ANIMATION_LENGTH)*((float)x-0.5*(float)length),15,	0.05*width+((float)counter/(float)ANIMATION_LENGTH)*((float)z-0.05*(float)width));
	white.SetPosition(0.95*(float)length+((float)counter/(float)ANIMATION_LENGTH)*((float)x-0.95*(float)length),15,	0.05*width+((float)counter/(float)ANIMATION_LENGTH)*((float)z-0.05*(float)width));
	magenta.SetPosition(0.05*(float)length+((float)counter/(float)ANIMATION_LENGTH)*((float)x-0.05*(float)length),15,	0.95*width+((float)counter/(float)ANIMATION_LENGTH)*((float)z-0.95*(float)width));
	cyan.SetPosition(0.5*(float)length+((float)counter/(float)ANIMATION_LENGTH)*((float)x-0.5*(float)length),15,	0.95*width+((float)counter/(float)ANIMATION_LENGTH)*((float)z-0.95*(float)width));
	red.SetPosition(0.95*(float)length+((float)counter/(float)ANIMATION_LENGTH)*((float)x-0.95*(float)length),15,	0.95*width+((float)counter/(float)ANIMATION_LENGTH)*((float)z-0.95*(float)width));
	counter++;
		}else 
		{
		animation =false;
		blue.Enable(false);
		yellow.Enable(false);
		white.Enable(false);
		magenta.Enable(false);
		cyan.Enable(false);
		red.Enable(false);
			}
	blue.Render();
	yellow.Render();
	white.Render();
	magenta.Render();
	cyan.Render();
	red.Render();

	}
void InitLight::Disable()
	{
		blue.Enable(false);
	yellow.Enable(false);
	white.Enable(false);
	magenta.Enable(false);
	cyan.Enable(false);
	red.Enable(false);
	}